// 基础菜单 - 所有角色都可以访问
export const baseMenus = [
  {
    path: '/welcome',
    title: '欢迎页',
    icon: 'House'
  }
]

// 账户管理菜单
export const accountMenu = {
  path: '/account',
  title: '账户管理',
  icon: 'User',
  children: [
    {
      path: '/account/profile',
      title: '个人信息'
    }
  ]
}

// 管理员菜单
export const adminMenus = [
  {
    path: '/system',
    title: '系统管理',
    icon: 'Setting',
    children: [
      {
        path: '/system/user',
        title: '用户管理'
      },
      {
        path: '/system/role',
        title: '角色管理'
      },
      {
        path: '/system/log',
        title: '日志管理',
        hidden: true,
        children: [
          {
            path: '/system/log/operation',
            title: '操作日志',
            hidden: true
          },
          {
            path: '/system/log/login',
            title: '登录日志',
            hidden: true
          },
          {
            path: '/system/log/error',
            title: '异常日志',
            hidden: true
          }
        ]
      }
    ]
  },
  {
    title: '产品管理',
    icon: 'Goods',
    path: '/product',
    children: [
      {
        path: '/product/list',
        title: '产品列表'
      },
      {
        path: '/product/category',
        title: '产品分类'
      },
      {
        path: '/product/approval',
        title: '产品审核',
        hidden: true
      },
      {
        path: '/product/marketing',
        title: '营销管理'
      }
    ]
  },
  {
    title: '贷款管理',
    icon: 'Money',
    path: '/loan',
    children: [
      {
        path: '/loan/list',
        title: '贷款列表'
      },
      {
        path: '/loan/apply',
        title: '贷款申请'
      },
      {
        path: '/loan/approval',
        title: '贷款审批'
      }
    ]
  },
  {
    title: '客户管理',
    icon: 'User',
    path: '/customer',
    children: [
      {
        path: '/customer/list',
        title: '客户列表'
      }
    ]
  },
  {
    title: '合同管理',
    icon: 'Document',
    path: '/contract',
    children: [
      {
        path: '/contract/list',
        title: '合同列表'
      },
      {
        path: '/contract/create',
        title: '生成合同'
      }
    ]
  },
  {
    title: '还款管理',
    icon: 'Money',
    path: '/repayment',
    children: [
      {
        path: '/repayment/plan',
        title: '还款计划'
      },
      {
        path: '/repayment/record',
        title: '还款记录',
        hidden: true
      },
      {
        path: '/repayment/overdue',
        title: '逾期管理'
      }
    ]
  },
  {
    title: '贷后管理',
    icon: 'Warning',
    path: '/postloan',
    hidden: true,
    children: [
      {
        path: '/postloan/inspection',
        title: '贷后检查'
      },
      {
        path: '/postloan/track',
        title: '贷后跟踪'
      },
      {
        path: '/postloan/assessment',
        title: '贷后评估'
      },
      {
        path: '/postloan/warning',
        title: '贷后预警'
      }
    ]
  },
  {
    title: '统计报表',
    icon: 'PieChart',
    path: '/report',
    children: [
      {
        path: '/report/business',
        title: '业务报表',
        hidden: true
      },
      {
        path: '/report/loan',
        title: '贷款报表'
      }
    ]
  }
]

// 财务人员菜单
export const financeMenus = [
  {
    title: '放款管理',
    icon: 'CreditCard',
    path: '/lending',
    children: [
      {
        path: '/lending/list',
        title: '放款列表'
      },
      {
        path: '/lending/process',
        title: '放款处理'
      }
    ]
  }
]

// 审批人员菜单
export const auditorMenus = [
  {
    title: '审批管理',
    icon: 'Document',
    path: '/approval',
    children: [
      {
        path: '/loan/approval',
        title: '贷款审批'
      },
      {
        path: '/lending/approval',
        title: '放款审批'
      }
    ]
  },
  {
    title: '产品管理',
    icon: 'Goods',
    path: '/product',
    children: [
      {
        path: '/product/list',
        title: '产品列表'
      },
      {
        path: '/product/category',
        title: '产品分类'
      },
      {
        path: '/product/approval',
        title: '产品审核',
        hidden: true
      }
    ]
  }
]

// 普通用户菜单
export const userMenus = [
  {
    title: '贷款管理',
    icon: 'Money',
    path: '/loan',
    children: [
      {
        path: '/loan/list',
        title: '贷款列表'
      },
      {
        path: '/loan/apply',
        title: '贷款申请'
      }
    ]
  },
  {
    title: '客户管理',
    icon: 'User',
    path: '/customer',
    children: [
      {
        path: '/customer/list',
        title: '客户列表'
      }
    ]
  },
  {
    title: '合同管理',
    icon: 'Document',
    path: '/contract',
    children: [
      {
        path: '/contract/list',
        title: '合同列表'
      },
      {
        path: '/contract/create',
        title: '生成合同'
      }
    ]
  },
  {
    title: '还款管理',
    icon: 'Money',
    path: '/repayment',
    children: [
      {
        path: '/repayment/plan',
        title: '还款计划'
      },
      {
        path: '/repayment/record',
        title: '还款记录',
        hidden: true
      },
      {
        path: '/repayment/overdue',
        title: '逾期管理'
      }
    ]
  }
]

// 生成菜单函数
export function generateMenusByRole(role) {
  // 添加基础菜单和账户管理菜单
  let menus = [...baseMenus]
  
  // 根据角色添加账户管理菜单
  const clonedAccountMenu = JSON.parse(JSON.stringify(accountMenu))
  if (role === 'admin') {
    clonedAccountMenu.children.push({
      path: '/account/list',
      title: '账户列表'
    })
  }
  menus.push(clonedAccountMenu)

  // 根据角色添加特定菜单
  switch (role) {
    case 'admin':
      menus = [...menus, ...adminMenus]
      break
    case 'finance':
      menus = [...menus, ...financeMenus]
      break
    case 'auditor':
      menus = [...menus, ...auditorMenus]
      break
    case 'user':
      menus = [...menus, ...userMenus]
      break
  }
  console.log('menus',menus)
  return menus
}